package com.guilin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.guilin.system.service.SurveyQuestionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.guilin.common.core.controller.BaseController;
import com.guilin.common.core.domain.AjaxResult;
import com.guilin.domain.SurveyQuestion;
import com.guilin.common.utils.poi.ExcelUtil;
import com.guilin.common.core.page.TableDataInfo;

/**
 * 题目Controller
 * 
 * @author xiaoqi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/admin-management/question")
public class SurveyQuestionController extends BaseController
{
    @Autowired
    private SurveyQuestionService surveyQuestionService;

    /**
     * 查询题目列表
     */
    @PreAuthorize("@ss.hasPermi('admin-management:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveyQuestion surveyQuestion)
    {
        startPage();
        List<SurveyQuestion> list = surveyQuestionService.selectSurveyQuestionList(surveyQuestion);
        return getDataTable(list);
    }

    /**
     * 导出题目列表
     */
    @PreAuthorize("@ss.hasPermi('admin-management:question:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurveyQuestion surveyQuestion)
    {
        List<SurveyQuestion> list = surveyQuestionService.selectSurveyQuestionList(surveyQuestion);
        ExcelUtil<SurveyQuestion> util = new ExcelUtil<SurveyQuestion>(SurveyQuestion.class);
        util.exportExcel(response, list, "题目数据");
    }

    /**
     * 获取题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin-management:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surveyQuestionService.selectSurveyQuestionById(id));
    }

    /**
     * 新增题目
     */
    @PreAuthorize("@ss.hasPermi('admin-management:question:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SurveyQuestion surveyQuestion)
    {
        return toAjax(surveyQuestionService.insertSurveyQuestion(surveyQuestion));
    }

    /**
     * 修改题目
     */
    @PreAuthorize("@ss.hasPermi('admin-management:question:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SurveyQuestion surveyQuestion)
    {
        return toAjax(surveyQuestionService.updateSurveyQuestion(surveyQuestion));
    }

    /**
     * 删除题目
     */
    @PreAuthorize("@ss.hasPermi('admin-management:question:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surveyQuestionService.deleteSurveyQuestionByIds(ids));
    }
}
